<style type="text/css">
    #hr-examineSimple-add {
        padding: 20px 25px 25px 0;
    }
</style>
<div class="layui-fluid" id="hr-examineSimple-add">
    <form class="layui-form" action="" lay-filter="hr-examineSimple-add-form">
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">试卷名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" minlength="2" maxlength="100" lay-verify="required|range|txt"
                       autocomplete="off" class="layui-input repetitive" id="hr-examineSimple-add-title">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">考试时长</label>
            <div class="layui-input-block">
                <input type="text" name="minutes" maxlength="11" lay-verify="range|txt|char|number"
                       autocomplete="off" class="layui-input repetitive" placeholder="分钟" >
            </div>
        </div>
        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="hr-examineSimple-add-submit"
                    id="hr-examineSimple-add-submit-btn"></button>
            <button type="reset" class="layui-btn" id="hr-examineSimple-add-reset-btn"></button>
        </div>
    </form>
</div>

<script>
    layui.use(['febs', 'form', 'validate','upload'], function () {
        let $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            // 表单
            form = layui.form,
            // 验证
            validate = layui.validate;
        // 进行表单验证
        form.verify(validate);
        // 渲染表单
        form.render();
        // hr-examineSimple-add-submit 为上方提交按钮的过滤器名称
        form.on('submit(hr-examineSimple-add-submit)', function (data) {
            // data.field为当前form表单的josn数据
            let title = data.field.title;
            $.ajax({
                type: 'get',
                url: 'examineSimple/isRepetitive',
                data: {"title": title},
                success:function(res){
                    if(res){
                        febs.post(ctx + 'examineSimple/add', data.field, function () {
                            // 关闭所有弹出窗体
                            layer.closeAll();
                            // 弹出成功消息
                            febs.alert.success('新增试卷成功');
                            // 点击父页面查询按钮
                            $('#hr-examineSimple').find('#hr-examineSimple-query-btn').click();
                        });
                    }else{
                        febs.alert.error("输入的试卷名称重复，请检查！");
                    }
                }
            });
            /*febs.post(ctx + 'examineSimple/add', data.field, function () {
                // 关闭所有弹出窗体
                layer.closeAll();
                // 弹出成功消息
                febs.alert.success('新增试卷成功');
                // 点击父页面查询按钮
                $('#hr-examineSimple').find('#hr-examineSimple-query-btn').click();
            });*/
            return false;
        });
    });
</script>